<template>
  <div>
    <!-- 标题 -->
    <h4 class="text-center">审批请假</h4>
    <!-- 展示列表 -->
    <table class="table table-bordered table-striped table-hover">
      <thead>
      <tr>
        <th>编号</th>
        <th>工号</th>
        <th>姓名</th>
        <th>所属部门</th>
        <th>请假类型</th>
        <th>请假开始时间</th>
        <th>请假结束时间</th>
        <th>请假原因</th>
        <th>审批操作</th>
      </tr>
      </thead>
      <tbody>
      <tr v-for="(item,index) in absentList" :key="item.id">
        <td>{{ item.a_ID }}</td>
        <td>{{ item.e_ID }}</td>
        <td>{{ nowname[index] }}</td>
        <td>部门{{ item.a_DEPARTMENT }}</td>
        <th>{{abtype[item.a_TYPE]}}</th>
        <td>{{ item.a_STTIME}}</td>
        <td>{{ item.a_ENDTIME }}</td>
        <td>{{ item.a_REASON}}</td>
        <td>
          <button type="button" class="btn btn-outline-success" @click="agree(item.a_ID)">同意</button>
          <button type="button" class="btn btn-outline-danger" @click="disagree(item.a_ID)">拒绝</button>
        </td>
      </tr>
      </tbody>
    </table>
  </div>
</template>

<script >
import axios from 'axios'
export default {
  name:'MyApproval',
  data(){
    return{
      absentList: [],
      nowname: [],
      abtype: ['因公请假', '年假','病假','婚假','产检假','产假','哺乳假','陪产假','事假'],
    }
  },
  mounted() {
    this.getAbsentList();
  },
  methods:{
    getAbsentList(){
      let that=this;
      let department = localStorage.getItem('department');
      let myurl = '/api/gmanager/absentlistnosolve'
      if(localStorage.getItem('job')==1)myurl = '/api/dmanager/absentlistnosolve/'+department;
      axios.get(myurl).then(res =>{
        // console.log(res.data.data[0].e_ID);
        this.absentList= res.data.data;
        for(let i = 0;i < this.absentList.length;i++){
          axios.get('/api/personnel/' + res.data.data[i].e_ID).then(res2 =>{
            that.nowname.push(res2.data.data.e_NAME);
          })
        }
        console.log(res.data.data);
      })

    },
    agree(id) {
      let myurl = '/api/gmanager/1'
      if(localStorage.getItem('job')==1)myurl = '/api/dmanager/1';
      axios.post(myurl,{
        a_ID:id,
      }).then(res=>{
        console.log(res.status);
      })
      this.$router.go(0)
    },
    disagree(id) {
      let myurl = '/api/gmanager/0'
      if(localStorage.getItem('job')==1)myurl = '/api/dmanager/0';
      axios.post(myurl,{
        a_ID:id,
      }).then(res=>{
        console.log(res.status);
      })
    }
  }
}
</script>
<style scoped lang="less">

</style>